from typing import List
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_month_strategy import BaseMonthStrategy

class FocusMonthUp(BaseMonthStrategy):
    """
    连续3天成交量降低策略，成交量逐日减少
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析过去3天的成交量是否连续降低
        """
        node_point = 0
        description = ""

        # 确保至少有3天的交易数据
        if len(trade_info_list) >= 3:
            # 检查过去3天的成交量是否连续减少
            for i in range(2, len(trade_info_list)):
                # 检查当前天成交量是否小于前一天的成交量
                if trade_info_list[i].vol < trade_info_list[i-1].vol:
                    node_point += 1  # 每天成交量减少得分 +1
                    description += f"Day {i}: Volume decreased compared to the previous day. "

                    # 如果当天成交量比前两天减少幅度较大，得分 +2
                    if trade_info_list[i].vol < trade_info_list[i-1].vol * 0.8:
                        node_point += 2
                        description += f"Day {i}: Volume decreased by more than 20% compared to the previous day. "

        # 创建策略信息对象
        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            confif=self.strategyConfig,
            node_point=node_point
        )

    def strategyConfig(self) -> dict:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="3DVD",
            strategy_name="Three Days Volume Decrease Strategy",
            strategy_group=0,  # 假设是风险型策略
            strategy_type="Volume Trend",
            analysis_day=3,
            strategy_level=2
        )
